package com.ymttest.database.sqlwapper;

import com.shop2cn.iapi.agentproducts.parameter.CatalogPriceDto;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.utils.MapUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/************************************************************************************
 * @File name : YmtUserWapper.java
 * @Author : zhouyi
 * @Date : 2015年4月2日
 * @Copyright : 洋码头 商品合库 新库
 ************************************************************************************/
public class YmtCatalogsIWapper {
	SqlManager manage;

	public YmtCatalogsIWapper() {
		manage = new SqlManager("intpro");
	}

	// 获取不重复商品Id
	public List<Map> selectProductIdBySku(String Sku) throws InterruptedException {
		List<Map> ret = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectProductIdBySku", Sku);
		manage.commit();
		return ret;
	}

	// 查询Ymt_Catalogs
	public List<YmtCatalogsI> selectCatalogsByProductId(String sProductId) throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<YmtCatalogsI> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByProductId", sProductId);
		manage.commit();
		return catalogslist;
	}

	// 查询Ymt_Catalogs
	public YmtCatalogsI selectCatalogsByCatalogId(String catalogId) throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<YmtCatalogsI> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByCatalogId", catalogId);
		manage.commit();
		return catalogslist.get(0);
	}

	public YmtCatalogsI selectCatalogsByParentCatalogId(String catalogId) throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<YmtCatalogsI> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByParentCatalogId", catalogId);
		manage.commit();
		return catalogslist.get(0);
	}

	public List<YmtCatalogsI> selectCatalogsByRootCatalogId(String catalogId) throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<YmtCatalogsI> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByRootCatalogId", catalogId);
		manage.commit();
		return catalogslist;
	}

	public List<YmtCatalogsI> selectCatalogsByCatalogIdforList(String catalogId) throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<YmtCatalogsI> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByCatalogId", catalogId);
		manage.commit();
		return catalogslist;
	}

	// 查询Ymt_Catalogs
	public List<Map> selectCatalogsByProductIdforMap(String sProductId) throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByProductIdforMap", sProductId);
		manage.commit();
		return catalogslist;
	}

	public List<Map> selectCatalogAttributeByCatalogId(String catalogId) throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogAttributeByCatalogId", catalogId);
		manage.commit();
		return catalogslist;
	}

	public List<CatalogPriceDto> getPriceByCatalogIds(List<String> catalogIds) throws InterruptedException {
		Map m = new HashMap();
		m.put("catalogIds",catalogIds);
		List<CatalogPriceDto> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.getPriceByCatalogIds", m);
		manage.commit();
		return catalogslist;
	}

	/*
	 * sUser=wesper, iLimitNum=30, fFlight=0.00,
	 * sProductId=067f6d91-0a59-4fb5-b705-9f5c2469f788, IsNew=true, iNum=3,
	 * BondedQuantity=1, iUserId=3383, dAddTime=2016-06-1514: 11: 55.837,
	 * iExpire=36524, iCatalogType=2,
	 * sCatalogId=e920929b-53bb-4b84-af89-12232b006741, iAcceptReturn=0,
	 * DataVersion=[ B@a9cd3b1, fQuotePrice=100.00, iAction=0, iCatalogStatus=5,
	 * sSKU=ceshi100, iSKUType=0 }
	 */
	public List<Map> selectCatalogsByUserIdandSku(Integer uSerId, String Sku) throws InterruptedException {
		@SuppressWarnings("unchecked")
		Map<String, Object> mm = new HashMap<String, Object>();
		mm.put("uSerId", uSerId);
		mm.put("Sku", Sku);
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByUserIdandSku", mm);
		manage.commit();
		return catalogslist;
	}

	// 查询Ymt_ProductPicture
	public List<Map> selectProductPictureByProductId(String sProductId) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectProductPictureByProductId", sProductId);
		manage.commit();
		return catalogslist;
	}

	// 查询Ymt_ProductDescConfigWord
	public List<Map> selectProductDescConfigWordByProductId(String sProductId) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectProductDescConfigWordByProductId", sProductId);
		manage.commit();
		return catalogslist;
	}

	// 更新
	/**
	 * 这里写错了是按productID更新
	 * @param iNum
	 * @param productID
	 * @return
	 * @throws InterruptedException
	 */
	public int updatestocknumByProductID(int iNum, String productID) throws InterruptedException {
		Map m = new HashMap();
		m.put("iNum", iNum);
		m.put("productId", productID);
		int i = manage.update("com.ymttest.database.mapping.YmtCatalogsIMapper.updatestocknumByProductID", m);
		manage.commit();
		return i;
	}
//	updatestocknumByCatalogID
	public int updatestocknumByCatalogID(int iNum, String catalog) throws InterruptedException {
		Map m = new HashMap();
		m.put("iNum", iNum);
		m.put("catalog", catalog);
		int i = manage.update("com.ymttest.database.mapping.YmtCatalogsIMapper.updatestocknumByCatalogID", m);
		manage.commit();
		return i;
	}
	public int updatePreSaleByProductId(int preSale, String productID) throws InterruptedException {
		Map m = new HashMap();
		m.put("IsPreSale", preSale);
		m.put("productId", productID);
		int i = manage.update("com.ymttest.database.mapping.YmtCatalogsIMapper.updatePreSaleByProductId", m);
		manage.commit();
		return i;
	}

	// 查询
	public List<Map> selectCatalognamesforonelogs(Map m) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalognamesforonelogs", m);
		manage.commit();
		return catalogslist;
	}

	// 查询
	public List<Map> selectCatalognamesfortwologs(Map m) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalognamesfortwologs", m);
		manage.commit();
		return catalogslist;
	}

	// 查询商品最大单价
	public List<Map> selectMaxfQuotePrice(String sproductid) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectMaxfQuotePrice", sproductid);
		manage.commit();
		return catalogslist;
	}

	// 查询商品最小单价
	public List<Map> selectMinfQuotePrice(String sproductid) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectMinfQuotePrice", sproductid);
		manage.commit();
		return catalogslist;
	}

	// 查询商品最小单价
	public Map selectAllMinPrice(String sproductid) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectAllMinPrice", sproductid);
		return catalogslist.get(0);
	}

	public List<Map> selectNewPriceWithout0(String sproductid) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectNewPriceWithout0", sproductid);
		return catalogslist;
	}

	public List<Map> selectVipPriceWithout0(String sproductid) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectVipPriceWithout0", sproductid);
		return catalogslist;
	}

	// 查询商品最da单价
	public Map selectAllMaxPrice(String sproductid) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectAllMaxPrice", sproductid);
		return catalogslist.get(0);
	}

	// 查询商品库存总数
	public List<Map> selectSumStock(String sproductid) throws InterruptedException {
		List<Map> catalogslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectSumStock", sproductid);
		manage.commit();
		return catalogslist;
	}

	public int updateCatalogTypeByProductId(String productId, int catalogType) {
		int i = manage.update("com.ymttest.database.mapping.YmtCatalogsIMapper.updateCatalogTypeByProductId",
				MapUtil.hashMap("sProductId", productId, "iCatalogType", catalogType));
		manage.commit();
		return i;
	}

	// 根据商品id和sku查询
	public List<Map> selectCatalogsByProductIdandSku(String sProductId, String sSKU) throws InterruptedException {
		@SuppressWarnings("unchecked")
		Map m = new HashMap();
		m.put("sProductId", sProductId);
		m.put("Sku", sSKU);
		List<Map> sProductIdlist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByProductIdandSku", m);
		manage.commit();
		return sProductIdlist;
	}

	public List<Map> selectCatalogPropsByCatalogId(String catalogId) throws InterruptedException {
		@SuppressWarnings("unchecked")
		Map m = new HashMap();
		m.put("sCatalogId", catalogId);
		List<Map> sCatalogPropslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogPropsByCatalogId", m);
		return sCatalogPropslist;
	}

	public List<Map> selectCatalogSetAttributesByCatalogId(String catalogId) throws InterruptedException {
		@SuppressWarnings("unchecked")
		Map m = new HashMap();
		m.put("sCatalogId", catalogId);
		List<Map> sCatalogPropslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogSetAttributesByCatalogId", m);
		return sCatalogPropslist;
	}

	public int updateiActionByCatalogId(int action, String catalogId) throws InterruptedException {
		Map m = new HashMap();
		m.put("action", action);
		m.put("catalogId", catalogId);
		int i = manage.update("com.ymttest.database.mapping.YmtCatalogsIMapper.updateiActionByCatalogId", m);
		manage.commit();
		return i;
	}

    public static void main(String[] args) throws InterruptedException {
        YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
        ymtCatalogsIWapper.updatestocknumByCatalogID(0, "c2520638");

    }

}
